package me.yricky.hid.desktop

import androidx.compose.animation.Crossfade
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color

@Composable
fun AppState.Page(){
    MaterialTheme(
        colors = if(isSystemInDarkTheme()){
            darkColors().copy(
                background = Color(0xff333333),
                surface = Color(0xff222222),
                onBackground = Color(0xffcccccc)
            )
        }else{
            lightColors().copy(
                background = Color(0xffeeeeee),
                surface = Color(0xffffffff),
                onBackground = Color(0xff333333)
            )
        }
    ) {
        Surface(
            color = MaterialTheme.colors.background,
        ) {
            Row {
                NavigationRail {
                    NavigationRailItem(
                        selected = mainNav == mainNavHome,
                        icon = { Icon(Theme.Icons.home(),"") },
                        label = { Text("主页") },
                        onClick = { mainNav = mainNavHome }
                    )
                    NavigationRailItem(
                        selected = mainNav == mainNavDeviceList,
                        icon = { Icon(Theme.Icons.browse(),"") },
                        label = { Text("打开") },
                        onClick = { mainNav = mainNavDeviceList }
                    )
                    if(mainNavDebugTabs.openedDevices.isNotEmpty()){
                        NavigationRailItem(
                            selected = mainNav == mainNavDebugTabs,
                            icon = { Icon(Theme.Icons.terminal(),"") },
                            label = { Text("调试") },
                            onClick = { mainNav = mainNavDebugTabs }
                        )
                    }
                    Spacer(Modifier.weight(1f))
                    NavigationRailItem(
                        selected = mainNav == null,
                        icon = { Icon(Theme.Icons.setting(),"") },
                        label = { Text("设置") },
                        onClick = {  }
                    )
                }
                Crossfade(mainNav){
                    it.Content(Modifier.fillMaxHeight().weight(1f))
                }
            }
        }
    }
}